### The GIM root directory
GIMDIR = ../../..
GDIR=$(GIMDIR)
## LNMLIB/src root directory
LNMDIR = ..
OPTS = 
CC=gcc
CXX=g++

CFLAGS=-Wall $(DEBUG) $(DEFINITIONS) $(CINCLUDES) $(CMISCFLAGS) $(LIBDIRS) $(OPTS) `xml2-config --cflags`
CPPFLAGS=-Wall  $(DEBUG) $(EXCEPTIONS) $(CPPINCLUDES) \
				$(DEFINITIONS) $(CPPMISCFLAGS) $(LIBDIRS) $(OPTS)
DEBUG=-O2 -g3
CMISCFLAGS=
CPPMISCFLAGS=
DEFINITIONS=-DLINUX_OS -D_GNU_SOURCE -DOS_LINUX -DT_GROUND_MODEL_MAP_DEBUG
EXCEPTIONS=-fexceptions

CINCLUDES=-I. $(BBDT_INCLUDE) -I$(GIMDIR)/utils $(LNM_UTIL_INCLUDE)
CPPINCLUDES=-I. $(BBDT_INCLUDE) -I$(GIMDIR)/glutImageGUI -I$(GIMDIR)/ImageUtils/JPEGEncoder -I$(GIMDIR)/utils \
	$(LNM_UTIL_INCLUDE) -I$(GIMDIR)/glutgui
LIBDIRS=$(BBANNLIB)

LD=g++
LDFLAGS=$(LIBDIRS)

#LIBS=-lrt -lpthread -lGL -lGLU -lglut -ljpeg -lANN
LIBS=-lrt -lpthread -lssl `sdl-config  --libs` -lSDL_gfx -ljpeg -lGL -lGLU -lglut -lxml2

CSRCUTIL = $(GIMDIR)/utils/ownutils.c $(GIMDIR)/utils/owndebug.c

CPPIMAGEGUI = $(GIMDIR)/glutImageGUI/glutImageGUI.cpp
CPPJPEG = $(GIMDIR)/ImageUtils/JPEGEncoder/JPEGEncoder.cpp

SRCSC=$(CSRCUTIL) 
SRCSCPP=bbdt_test.cpp OccuGUI.cpp $(BBDT_SRC_CPP) $(CPPIMAGEGUI) $(CPPJPEG)

SLAMMER_CPP=$(BBDT_DIR)/MatchStorage.cpp $(BBDT_DIR)/EnvironmentMeasurement2D.cpp \
		$(BBDT_DIR)/BetBdtLocalizer.cpp BBSlammerWrapper.cpp $(CPPIMAGEGUI) $(CPPJPEG) $(GIMDIR)/glutgui/RGBImage.cpp
VPATH=

include Makefile.bbdt
include $(LNMDIR)/utils/Makefile.util
## Construct final lists of CPP and C objects
OBJSC=$(SRCSC:.c=.o)
OBJSCPP=$(SRCSCPP:.cpp=.opp)

PLOTUTIL_OBJSC=$(SRCSC:.c=.o)
PLOTUTIL_OBJSCPP=$(BBPLOTUTIL_CPP:.cpp=.opp)

SLAMMER_OBJ=$(SLAMMER_CPP:.cpp=.opp) $(UTIL_ALL_OBS_CPP)

## Define compiles and links
COMPILEC=$(CC) $(CFLAGS) $(CINCLUDES) -c
COMPILECPP=$(CXX) $(CPPFLAGS) $(CPPINCLUDES) -c
LINK=$(LD) $(LDFLAGS) 

.PHONY: all clean realclean

all: bbdt bbPlotUtilTester BBSlammerWrapperTester GridMatch

bbdt: $(OBJSC) $(OBJSCPP)
			$(LINK) -o $@ $(OBJSC) $(OBJSCPP) $(LIBS)
BBSlammerWrapperTester: $(UTIL_ALL_OBS_C) $(SLAMMER_OBJ) BBSlammerWrapperTester.opp
		$(LINK) -o $@ $(UTIL_ALL_OBS_C) $(SLAMMER_OBJ) BBSlammerWrapperTester.opp $(LIBS)
			

GridMatch: $(UTIL_ALL_OBS_C) $(SLAMMER_OBJ) GridMatch.opp
		$(LINK) -o $@ $(UTIL_ALL_OBS_C) $(SLAMMER_OBJ) GridMatch.opp $(LIBS)

bbPlotUtilTester: $(PLOTUTIL_OBJSC) $(PLOTUTIL_OBJSCPP) bbPlotUtilTester.opp
	$(LINK) -o $@ $(PLOTUTIL_OBJSC) $(PLOTUTIL_OBJSCPP) bbPlotUtilTester.opp $(LIBS)
			

clean: 
	rm -f *.opp *.o bbdt *.out *~ *.d *.dpp $(OBJSC) $(OBJSCPP) 

realclean:
	rm -f $(OBJSC) $(OBJSCPP) $(OBJ_LNM) $(OBJ_GSERVER_C) $(OBJ_GSERVER_CPP) $(OBJ_GCLIEN_C) $(OBJ_GCLIEN_CPP)\
 		bbdt *.out *~ *.d *.dpp *.opp *.o

##manual:
##	doxygen

## Compile rule for all .o (.c) file
%.o:    %.c
				$(COMPILEC) -o $@ $<

## Compile rule for all .opp (.cpp) files
%.opp:	%.cpp
				$(COMPILECPP) -o $@ $<
